{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import math\n",
    "from sklearn.cluster import KMeans\n",
    "players = pd.read_csv('./data/nba-player-2014.csv', na_values='-')\n",
    "players.fillna(0, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>FTA/G</th>\n",
       "      <th>MPG</th>\n",
       "      <th>FT%</th>\n",
       "      <th>PPG</th>\n",
       "      <th>GP</th>\n",
       "      <th>FGM/G</th>\n",
       "      <th>3FGA/G</th>\n",
       "      <th>3FG%</th>\n",
       "      <th>HIGH</th>\n",
       "      <th>PPS</th>\n",
       "      <th>3FGM/G</th>\n",
       "      <th>FTM/G</th>\n",
       "      <th>FG%</th>\n",
       "      <th>PTS/48</th>\n",
       "      <th>GS</th>\n",
       "      <th>fullname</th>\n",
       "      <th>PTS</th>\n",
       "      <th>FGA/G</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9.8</td>\n",
       "      <td>34.4</td>\n",
       "      <td>0.835</td>\n",
       "      <td>28.1</td>\n",
       "      <td>67</td>\n",
       "      <td>9.4</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.299</td>\n",
       "      <td>54</td>\n",
       "      <td>1.28</td>\n",
       "      <td>1.3</td>\n",
       "      <td>8.1</td>\n",
       "      <td>0.426</td>\n",
       "      <td>39.3</td>\n",
       "      <td>67</td>\n",
       "      <td>Westbrook, Russell</td>\n",
       "      <td>1886</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.2</td>\n",
       "      <td>36.8</td>\n",
       "      <td>0.868</td>\n",
       "      <td>27.4</td>\n",
       "      <td>81</td>\n",
       "      <td>8.0</td>\n",
       "      <td>6.9</td>\n",
       "      <td>0.375</td>\n",
       "      <td>51</td>\n",
       "      <td>1.51</td>\n",
       "      <td>2.6</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.440</td>\n",
       "      <td>35.7</td>\n",
       "      <td>81</td>\n",
       "      <td>Harden, James</td>\n",
       "      <td>2217</td>\n",
       "      <td>18.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7.7</td>\n",
       "      <td>36.1</td>\n",
       "      <td>0.710</td>\n",
       "      <td>25.3</td>\n",
       "      <td>69</td>\n",
       "      <td>9.0</td>\n",
       "      <td>4.9</td>\n",
       "      <td>0.354</td>\n",
       "      <td>42</td>\n",
       "      <td>1.36</td>\n",
       "      <td>1.7</td>\n",
       "      <td>5.4</td>\n",
       "      <td>0.488</td>\n",
       "      <td>33.6</td>\n",
       "      <td>69</td>\n",
       "      <td>James, LeBron</td>\n",
       "      <td>1743</td>\n",
       "      <td>18.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6.8</td>\n",
       "      <td>36.1</td>\n",
       "      <td>0.805</td>\n",
       "      <td>24.4</td>\n",
       "      <td>68</td>\n",
       "      <td>9.4</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.083</td>\n",
       "      <td>43</td>\n",
       "      <td>1.38</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>0.535</td>\n",
       "      <td>32.4</td>\n",
       "      <td>68</td>\n",
       "      <td>Davis, Anthony</td>\n",
       "      <td>1656</td>\n",
       "      <td>17.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9.2</td>\n",
       "      <td>34.1</td>\n",
       "      <td>0.782</td>\n",
       "      <td>24.1</td>\n",
       "      <td>59</td>\n",
       "      <td>8.4</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.250</td>\n",
       "      <td>39</td>\n",
       "      <td>1.33</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7.2</td>\n",
       "      <td>0.467</td>\n",
       "      <td>33.9</td>\n",
       "      <td>59</td>\n",
       "      <td>Cousins, DeMarcus</td>\n",
       "      <td>1421</td>\n",
       "      <td>18.1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   FTA/G   MPG    FT%   PPG  GP  FGM/G  3FGA/G   3FG%  HIGH   PPS  3FGM/G  \\\n",
       "0    9.8  34.4  0.835  28.1  67    9.4     4.3  0.299    54  1.28     1.3   \n",
       "1   10.2  36.8  0.868  27.4  81    8.0     6.9  0.375    51  1.51     2.6   \n",
       "2    7.7  36.1  0.710  25.3  69    9.0     4.9  0.354    42  1.36     1.7   \n",
       "3    6.8  36.1  0.805  24.4  68    9.4     0.2  0.083    43  1.38     0.0   \n",
       "4    9.2  34.1  0.782  24.1  59    8.4     0.1  0.250    39  1.33     0.0   \n",
       "\n",
       "   FTM/G    FG%  PTS/48  GS            fullname   PTS  FGA/G  \n",
       "0    8.1  0.426    39.3  67  Westbrook, Russell  1886   22.0  \n",
       "1    8.8  0.440    35.7  81       Harden, James  2217   18.1  \n",
       "2    5.4  0.488    33.6  69       James, LeBron  1743   18.5  \n",
       "3    5.5  0.535    32.4  68      Davis, Anthony  1656   17.6  \n",
       "4    7.2  0.467    33.9  59   Cousins, DeMarcus  1421   18.1  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "players.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "distance_excluded_columns = ['fullname']\n",
    "distance_columns = list(set(players.columns) - set(distance_excluded_columns))\n",
    "distance_stat = players[distance_columns]\n",
    "normalized_stat = (distance_stat - distance_stat.mean()) / distance_stat.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 4, 1, 2, 1, 2, 2, 4, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 4,\n",
       "       1, 1, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 4,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1,\n",
       "       1, 4, 1, 4, 4, 1, 1, 1, 4, 1, 4, 1, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1,\n",
       "       4, 1, 4, 4, 1, 4, 1, 4, 4, 3, 1, 4, 1, 1, 1, 1, 1, 3, 3, 3, 1, 4,\n",
       "       1, 4, 4, 4, 1, 3, 1, 1, 4, 1, 4, 3, 1, 3, 3, 3, 1, 4, 3, 3, 3, 4,\n",
       "       0, 0, 4, 4, 0, 3, 0, 3, 3, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3,\n",
       "       3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 3, 0, 0, 3, 3, 3, 3, 3, 0,\n",
       "       3, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 0, 3, 3, 0, 3, 3, 3,\n",
       "       3, 0, 3, 0, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 0, 0, 3, 3, 0, 3, 3, 0,\n",
       "       3, 3, 3, 0, 0, 0, 3, 3, 0, 3, 0, 0, 3, 3, 3, 0, 0, 3, 3, 0, 0, 0,\n",
       "       0, 0, 0], dtype=int32)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kmeans = KMeans(n_clusters=5, random_state=40)\n",
    "kmeans = kmeans.fit(normalized_stat)\n",
    "kmeans.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "players['Group'] = kmeans.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    43\n",
       "1    79\n",
       "2    29\n",
       "3    80\n",
       "4    36\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "players.groupby(kmeans.labels_).count().max(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>FTA/G</th>\n",
       "      <th>MPG</th>\n",
       "      <th>FT%</th>\n",
       "      <th>PPG</th>\n",
       "      <th>GP</th>\n",
       "      <th>FGM/G</th>\n",
       "      <th>3FGA/G</th>\n",
       "      <th>3FG%</th>\n",
       "      <th>HIGH</th>\n",
       "      <th>PPS</th>\n",
       "      <th>3FGM/G</th>\n",
       "      <th>FTM/G</th>\n",
       "      <th>FG%</th>\n",
       "      <th>PTS/48</th>\n",
       "      <th>GS</th>\n",
       "      <th>fullname</th>\n",
       "      <th>PTS</th>\n",
       "      <th>FGA/G</th>\n",
       "      <th>Group</th>\n",
       "      <th>Distance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7.7</td>\n",
       "      <td>36.1</td>\n",
       "      <td>0.710</td>\n",
       "      <td>25.3</td>\n",
       "      <td>69</td>\n",
       "      <td>9.0</td>\n",
       "      <td>4.9</td>\n",
       "      <td>0.354</td>\n",
       "      <td>42</td>\n",
       "      <td>1.36</td>\n",
       "      <td>1.7</td>\n",
       "      <td>5.4</td>\n",
       "      <td>0.488</td>\n",
       "      <td>33.6</td>\n",
       "      <td>69</td>\n",
       "      <td>James, LeBron</td>\n",
       "      <td>1743</td>\n",
       "      <td>18.5</td>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5.8</td>\n",
       "      <td>35.4</td>\n",
       "      <td>0.858</td>\n",
       "      <td>21.1</td>\n",
       "      <td>68</td>\n",
       "      <td>7.5</td>\n",
       "      <td>3.2</td>\n",
       "      <td>0.359</td>\n",
       "      <td>40</td>\n",
       "      <td>1.28</td>\n",
       "      <td>1.2</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.455</td>\n",
       "      <td>28.5</td>\n",
       "      <td>67</td>\n",
       "      <td>Gay, Rudy</td>\n",
       "      <td>1432</td>\n",
       "      <td>16.4</td>\n",
       "      <td>2</td>\n",
       "      <td>2.928869</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>6.1</td>\n",
       "      <td>34.4</td>\n",
       "      <td>0.812</td>\n",
       "      <td>19.3</td>\n",
       "      <td>76</td>\n",
       "      <td>6.4</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.364</td>\n",
       "      <td>33</td>\n",
       "      <td>1.35</td>\n",
       "      <td>1.6</td>\n",
       "      <td>4.9</td>\n",
       "      <td>0.445</td>\n",
       "      <td>26.8</td>\n",
       "      <td>76</td>\n",
       "      <td>Hayward, Gordon</td>\n",
       "      <td>1463</td>\n",
       "      <td>14.3</td>\n",
       "      <td>2</td>\n",
       "      <td>3.423804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>6.0</td>\n",
       "      <td>31.8</td>\n",
       "      <td>0.768</td>\n",
       "      <td>21.5</td>\n",
       "      <td>62</td>\n",
       "      <td>8.2</td>\n",
       "      <td>1.6</td>\n",
       "      <td>0.284</td>\n",
       "      <td>42</td>\n",
       "      <td>1.23</td>\n",
       "      <td>0.5</td>\n",
       "      <td>4.6</td>\n",
       "      <td>0.470</td>\n",
       "      <td>32.4</td>\n",
       "      <td>62</td>\n",
       "      <td>Wade, Dwyane</td>\n",
       "      <td>1331</td>\n",
       "      <td>17.5</td>\n",
       "      <td>2</td>\n",
       "      <td>3.485929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>4.9</td>\n",
       "      <td>36.4</td>\n",
       "      <td>0.863</td>\n",
       "      <td>21.7</td>\n",
       "      <td>75</td>\n",
       "      <td>7.7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.415</td>\n",
       "      <td>57</td>\n",
       "      <td>1.32</td>\n",
       "      <td>2.1</td>\n",
       "      <td>4.2</td>\n",
       "      <td>0.468</td>\n",
       "      <td>28.6</td>\n",
       "      <td>75</td>\n",
       "      <td>Irving, Kyrie</td>\n",
       "      <td>1628</td>\n",
       "      <td>16.5</td>\n",
       "      <td>2</td>\n",
       "      <td>3.555443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>7.1</td>\n",
       "      <td>38.7</td>\n",
       "      <td>0.834</td>\n",
       "      <td>20.0</td>\n",
       "      <td>65</td>\n",
       "      <td>6.5</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.378</td>\n",
       "      <td>35</td>\n",
       "      <td>1.43</td>\n",
       "      <td>1.1</td>\n",
       "      <td>5.9</td>\n",
       "      <td>0.462</td>\n",
       "      <td>24.8</td>\n",
       "      <td>65</td>\n",
       "      <td>Butler, Jimmy</td>\n",
       "      <td>1301</td>\n",
       "      <td>14.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3.649827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5.1</td>\n",
       "      <td>35.4</td>\n",
       "      <td>0.845</td>\n",
       "      <td>23.4</td>\n",
       "      <td>71</td>\n",
       "      <td>9.3</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.352</td>\n",
       "      <td>39</td>\n",
       "      <td>1.17</td>\n",
       "      <td>0.5</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.466</td>\n",
       "      <td>31.7</td>\n",
       "      <td>71</td>\n",
       "      <td>Aldridge, LaMarcus</td>\n",
       "      <td>1661</td>\n",
       "      <td>19.9</td>\n",
       "      <td>2</td>\n",
       "      <td>3.667809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>6.4</td>\n",
       "      <td>35.2</td>\n",
       "      <td>0.728</td>\n",
       "      <td>21.9</td>\n",
       "      <td>67</td>\n",
       "      <td>8.6</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.400</td>\n",
       "      <td>45</td>\n",
       "      <td>1.28</td>\n",
       "      <td>0.1</td>\n",
       "      <td>4.6</td>\n",
       "      <td>0.502</td>\n",
       "      <td>29.9</td>\n",
       "      <td>67</td>\n",
       "      <td>Griffin, Blake</td>\n",
       "      <td>1469</td>\n",
       "      <td>17.1</td>\n",
       "      <td>2</td>\n",
       "      <td>3.685176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9.8</td>\n",
       "      <td>34.4</td>\n",
       "      <td>0.835</td>\n",
       "      <td>28.1</td>\n",
       "      <td>67</td>\n",
       "      <td>9.4</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.299</td>\n",
       "      <td>54</td>\n",
       "      <td>1.28</td>\n",
       "      <td>1.3</td>\n",
       "      <td>8.1</td>\n",
       "      <td>0.426</td>\n",
       "      <td>39.3</td>\n",
       "      <td>67</td>\n",
       "      <td>Westbrook, Russell</td>\n",
       "      <td>1886</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3.722021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>4.9</td>\n",
       "      <td>35.7</td>\n",
       "      <td>0.864</td>\n",
       "      <td>21.0</td>\n",
       "      <td>82</td>\n",
       "      <td>7.2</td>\n",
       "      <td>7.0</td>\n",
       "      <td>0.343</td>\n",
       "      <td>43</td>\n",
       "      <td>1.26</td>\n",
       "      <td>2.4</td>\n",
       "      <td>4.2</td>\n",
       "      <td>0.434</td>\n",
       "      <td>28.2</td>\n",
       "      <td>82</td>\n",
       "      <td>Lillard, Damian</td>\n",
       "      <td>1720</td>\n",
       "      <td>16.6</td>\n",
       "      <td>2</td>\n",
       "      <td>3.967624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6.8</td>\n",
       "      <td>36.1</td>\n",
       "      <td>0.805</td>\n",
       "      <td>24.4</td>\n",
       "      <td>68</td>\n",
       "      <td>9.4</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.083</td>\n",
       "      <td>43</td>\n",
       "      <td>1.38</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>0.535</td>\n",
       "      <td>32.4</td>\n",
       "      <td>68</td>\n",
       "      <td>Davis, Anthony</td>\n",
       "      <td>1656</td>\n",
       "      <td>17.6</td>\n",
       "      <td>2</td>\n",
       "      <td>4.088982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9.2</td>\n",
       "      <td>34.1</td>\n",
       "      <td>0.782</td>\n",
       "      <td>24.1</td>\n",
       "      <td>59</td>\n",
       "      <td>8.4</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.250</td>\n",
       "      <td>39</td>\n",
       "      <td>1.33</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7.2</td>\n",
       "      <td>0.467</td>\n",
       "      <td>33.9</td>\n",
       "      <td>59</td>\n",
       "      <td>Cousins, DeMarcus</td>\n",
       "      <td>1421</td>\n",
       "      <td>18.1</td>\n",
       "      <td>2</td>\n",
       "      <td>4.297432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>7.2</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0.832</td>\n",
       "      <td>20.1</td>\n",
       "      <td>60</td>\n",
       "      <td>6.8</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.284</td>\n",
       "      <td>42</td>\n",
       "      <td>1.22</td>\n",
       "      <td>0.4</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.413</td>\n",
       "      <td>27.5</td>\n",
       "      <td>60</td>\n",
       "      <td>DeRozan, DeMar</td>\n",
       "      <td>1204</td>\n",
       "      <td>16.5</td>\n",
       "      <td>2</td>\n",
       "      <td>4.327920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>4.4</td>\n",
       "      <td>35.7</td>\n",
       "      <td>0.819</td>\n",
       "      <td>17.9</td>\n",
       "      <td>72</td>\n",
       "      <td>6.6</td>\n",
       "      <td>3.4</td>\n",
       "      <td>0.339</td>\n",
       "      <td>38</td>\n",
       "      <td>1.19</td>\n",
       "      <td>1.2</td>\n",
       "      <td>3.6</td>\n",
       "      <td>0.436</td>\n",
       "      <td>24.1</td>\n",
       "      <td>71</td>\n",
       "      <td>Oladipo, Victor</td>\n",
       "      <td>1292</td>\n",
       "      <td>15.1</td>\n",
       "      <td>2</td>\n",
       "      <td>4.499264</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>3.9</td>\n",
       "      <td>34.8</td>\n",
       "      <td>0.900</td>\n",
       "      <td>19.1</td>\n",
       "      <td>82</td>\n",
       "      <td>6.9</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.398</td>\n",
       "      <td>41</td>\n",
       "      <td>1.34</td>\n",
       "      <td>1.7</td>\n",
       "      <td>3.5</td>\n",
       "      <td>0.485</td>\n",
       "      <td>26.3</td>\n",
       "      <td>82</td>\n",
       "      <td>Paul, Chris</td>\n",
       "      <td>1564</td>\n",
       "      <td>14.3</td>\n",
       "      <td>2</td>\n",
       "      <td>4.502929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>4.5</td>\n",
       "      <td>34.5</td>\n",
       "      <td>0.808</td>\n",
       "      <td>17.8</td>\n",
       "      <td>70</td>\n",
       "      <td>6.1</td>\n",
       "      <td>5.6</td>\n",
       "      <td>0.338</td>\n",
       "      <td>39</td>\n",
       "      <td>1.19</td>\n",
       "      <td>1.9</td>\n",
       "      <td>3.6</td>\n",
       "      <td>0.412</td>\n",
       "      <td>24.7</td>\n",
       "      <td>70</td>\n",
       "      <td>Lowry, Kyle</td>\n",
       "      <td>1244</td>\n",
       "      <td>14.9</td>\n",
       "      <td>2</td>\n",
       "      <td>4.541434</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>5.4</td>\n",
       "      <td>34.6</td>\n",
       "      <td>0.800</td>\n",
       "      <td>17.0</td>\n",
       "      <td>81</td>\n",
       "      <td>5.8</td>\n",
       "      <td>3.4</td>\n",
       "      <td>0.324</td>\n",
       "      <td>34</td>\n",
       "      <td>1.32</td>\n",
       "      <td>1.1</td>\n",
       "      <td>4.4</td>\n",
       "      <td>0.447</td>\n",
       "      <td>23.6</td>\n",
       "      <td>81</td>\n",
       "      <td>Bledsoe, Eric</td>\n",
       "      <td>1377</td>\n",
       "      <td>12.9</td>\n",
       "      <td>2</td>\n",
       "      <td>4.626776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.2</td>\n",
       "      <td>36.8</td>\n",
       "      <td>0.868</td>\n",
       "      <td>27.4</td>\n",
       "      <td>81</td>\n",
       "      <td>8.0</td>\n",
       "      <td>6.9</td>\n",
       "      <td>0.375</td>\n",
       "      <td>51</td>\n",
       "      <td>1.51</td>\n",
       "      <td>2.6</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.440</td>\n",
       "      <td>35.7</td>\n",
       "      <td>81</td>\n",
       "      <td>Harden, James</td>\n",
       "      <td>2217</td>\n",
       "      <td>18.1</td>\n",
       "      <td>2</td>\n",
       "      <td>4.681894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>3.8</td>\n",
       "      <td>33.7</td>\n",
       "      <td>0.752</td>\n",
       "      <td>18.9</td>\n",
       "      <td>80</td>\n",
       "      <td>7.5</td>\n",
       "      <td>3.6</td>\n",
       "      <td>0.285</td>\n",
       "      <td>38</td>\n",
       "      <td>1.12</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.9</td>\n",
       "      <td>0.445</td>\n",
       "      <td>26.9</td>\n",
       "      <td>80</td>\n",
       "      <td>Ellis, Monta</td>\n",
       "      <td>1513</td>\n",
       "      <td>16.9</td>\n",
       "      <td>2</td>\n",
       "      <td>4.712634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>4.6</td>\n",
       "      <td>32.7</td>\n",
       "      <td>0.757</td>\n",
       "      <td>16.7</td>\n",
       "      <td>73</td>\n",
       "      <td>6.1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.356</td>\n",
       "      <td>30</td>\n",
       "      <td>1.31</td>\n",
       "      <td>1.1</td>\n",
       "      <td>3.5</td>\n",
       "      <td>0.476</td>\n",
       "      <td>24.5</td>\n",
       "      <td>73</td>\n",
       "      <td>Millsap, Paul</td>\n",
       "      <td>1218</td>\n",
       "      <td>12.7</td>\n",
       "      <td>2</td>\n",
       "      <td>4.788322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>3.3</td>\n",
       "      <td>31.9</td>\n",
       "      <td>0.879</td>\n",
       "      <td>21.7</td>\n",
       "      <td>77</td>\n",
       "      <td>7.8</td>\n",
       "      <td>7.1</td>\n",
       "      <td>0.439</td>\n",
       "      <td>52</td>\n",
       "      <td>1.28</td>\n",
       "      <td>3.1</td>\n",
       "      <td>2.9</td>\n",
       "      <td>0.463</td>\n",
       "      <td>32.6</td>\n",
       "      <td>77</td>\n",
       "      <td>Thompson, Klay</td>\n",
       "      <td>1668</td>\n",
       "      <td>16.9</td>\n",
       "      <td>2</td>\n",
       "      <td>4.834636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>4.6</td>\n",
       "      <td>35.9</td>\n",
       "      <td>0.785</td>\n",
       "      <td>17.6</td>\n",
       "      <td>79</td>\n",
       "      <td>6.6</td>\n",
       "      <td>2.7</td>\n",
       "      <td>0.300</td>\n",
       "      <td>34</td>\n",
       "      <td>1.19</td>\n",
       "      <td>0.8</td>\n",
       "      <td>3.6</td>\n",
       "      <td>0.445</td>\n",
       "      <td>23.5</td>\n",
       "      <td>79</td>\n",
       "      <td>Wall, John</td>\n",
       "      <td>1387</td>\n",
       "      <td>14.8</td>\n",
       "      <td>2</td>\n",
       "      <td>4.851901</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>4.2</td>\n",
       "      <td>32.7</td>\n",
       "      <td>0.914</td>\n",
       "      <td>23.8</td>\n",
       "      <td>80</td>\n",
       "      <td>8.2</td>\n",
       "      <td>8.1</td>\n",
       "      <td>0.443</td>\n",
       "      <td>51</td>\n",
       "      <td>1.42</td>\n",
       "      <td>3.6</td>\n",
       "      <td>3.9</td>\n",
       "      <td>0.487</td>\n",
       "      <td>34.9</td>\n",
       "      <td>80</td>\n",
       "      <td>Curry, Stephen</td>\n",
       "      <td>1900</td>\n",
       "      <td>16.8</td>\n",
       "      <td>2</td>\n",
       "      <td>4.887398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>4.7</td>\n",
       "      <td>34.4</td>\n",
       "      <td>0.803</td>\n",
       "      <td>18.5</td>\n",
       "      <td>78</td>\n",
       "      <td>7.3</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.462</td>\n",
       "      <td>46</td>\n",
       "      <td>1.25</td>\n",
       "      <td>0.2</td>\n",
       "      <td>3.8</td>\n",
       "      <td>0.494</td>\n",
       "      <td>25.9</td>\n",
       "      <td>78</td>\n",
       "      <td>Gasol, Pau</td>\n",
       "      <td>1446</td>\n",
       "      <td>14.8</td>\n",
       "      <td>2</td>\n",
       "      <td>4.989331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>3.8</td>\n",
       "      <td>29.6</td>\n",
       "      <td>0.882</td>\n",
       "      <td>17.3</td>\n",
       "      <td>77</td>\n",
       "      <td>6.3</td>\n",
       "      <td>3.6</td>\n",
       "      <td>0.380</td>\n",
       "      <td>30</td>\n",
       "      <td>1.26</td>\n",
       "      <td>1.4</td>\n",
       "      <td>3.3</td>\n",
       "      <td>0.459</td>\n",
       "      <td>28.0</td>\n",
       "      <td>77</td>\n",
       "      <td>Nowitzki, Dirk</td>\n",
       "      <td>1333</td>\n",
       "      <td>13.8</td>\n",
       "      <td>2</td>\n",
       "      <td>5.007452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>4.6</td>\n",
       "      <td>34.2</td>\n",
       "      <td>0.827</td>\n",
       "      <td>17.3</td>\n",
       "      <td>62</td>\n",
       "      <td>6.1</td>\n",
       "      <td>4.5</td>\n",
       "      <td>0.304</td>\n",
       "      <td>42</td>\n",
       "      <td>1.10</td>\n",
       "      <td>1.4</td>\n",
       "      <td>3.8</td>\n",
       "      <td>0.385</td>\n",
       "      <td>24.4</td>\n",
       "      <td>58</td>\n",
       "      <td>Walker, Kemba</td>\n",
       "      <td>1075</td>\n",
       "      <td>15.8</td>\n",
       "      <td>2</td>\n",
       "      <td>5.170208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>5.7</td>\n",
       "      <td>36.2</td>\n",
       "      <td>0.760</td>\n",
       "      <td>16.9</td>\n",
       "      <td>82</td>\n",
       "      <td>6.1</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.310</td>\n",
       "      <td>33</td>\n",
       "      <td>1.22</td>\n",
       "      <td>0.5</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.437</td>\n",
       "      <td>22.4</td>\n",
       "      <td>82</td>\n",
       "      <td>Wiggins, Andrew</td>\n",
       "      <td>1387</td>\n",
       "      <td>13.9</td>\n",
       "      <td>2</td>\n",
       "      <td>5.178627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>5.4</td>\n",
       "      <td>33.2</td>\n",
       "      <td>0.795</td>\n",
       "      <td>17.4</td>\n",
       "      <td>81</td>\n",
       "      <td>6.5</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.176</td>\n",
       "      <td>33</td>\n",
       "      <td>1.32</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0.494</td>\n",
       "      <td>25.2</td>\n",
       "      <td>81</td>\n",
       "      <td>Gasol, Marc</td>\n",
       "      <td>1413</td>\n",
       "      <td>13.2</td>\n",
       "      <td>2</td>\n",
       "      <td>5.463590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2.9</td>\n",
       "      <td>34.2</td>\n",
       "      <td>0.752</td>\n",
       "      <td>19.3</td>\n",
       "      <td>74</td>\n",
       "      <td>8.5</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.333</td>\n",
       "      <td>37</td>\n",
       "      <td>1.18</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>0.523</td>\n",
       "      <td>27.1</td>\n",
       "      <td>74</td>\n",
       "      <td>Vucevic, Nikola</td>\n",
       "      <td>1428</td>\n",
       "      <td>16.3</td>\n",
       "      <td>2</td>\n",
       "      <td>5.780306</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    FTA/G   MPG    FT%   PPG  GP  FGM/G  3FGA/G   3FG%  HIGH   PPS  3FGM/G  \\\n",
       "2     7.7  36.1  0.710  25.3  69    9.0     4.9  0.354    42  1.36     1.7   \n",
       "11    5.8  35.4  0.858  21.1  68    7.5     3.2  0.359    40  1.28     1.2   \n",
       "15    6.1  34.4  0.812  19.3  76    6.4     4.3  0.364    33  1.35     1.6   \n",
       "10    6.0  31.8  0.768  21.5  62    8.2     1.6  0.284    42  1.23     0.5   \n",
       "8     4.9  36.4  0.863  21.7  75    7.7     5.0  0.415    57  1.32     2.1   \n",
       "14    7.1  38.7  0.834  20.0  65    6.5     3.0  0.378    35  1.43     1.1   \n",
       "6     5.1  35.4  0.845  23.4  71    9.3     1.5  0.352    39  1.17     0.5   \n",
       "7     6.4  35.2  0.728  21.9  67    8.6     0.4  0.400    45  1.28     0.1   \n",
       "0     9.8  34.4  0.835  28.1  67    9.4     4.3  0.299    54  1.28     1.3   \n",
       "12    4.9  35.7  0.864  21.0  82    7.2     7.0  0.343    43  1.26     2.4   \n",
       "3     6.8  36.1  0.805  24.4  68    9.4     0.2  0.083    43  1.38     0.0   \n",
       "4     9.2  34.1  0.782  24.1  59    8.4     0.1  0.250    39  1.33     0.0   \n",
       "13    7.2  35.0  0.832  20.1  60    6.8     1.5  0.284    42  1.22     0.4   \n",
       "20    4.4  35.7  0.819  17.9  72    6.6     3.4  0.339    38  1.19     1.2   \n",
       "17    3.9  34.8  0.900  19.1  82    6.9     4.3  0.398    41  1.34     1.7   \n",
       "21    4.5  34.5  0.808  17.8  70    6.1     5.6  0.338    39  1.19     1.9   \n",
       "28    5.4  34.6  0.800  17.0  81    5.8     3.4  0.324    34  1.32     1.1   \n",
       "1    10.2  36.8  0.868  27.4  81    8.0     6.9  0.375    51  1.51     2.6   \n",
       "18    3.8  33.7  0.752  18.9  80    7.5     3.6  0.285    38  1.12     1.0   \n",
       "31    4.6  32.7  0.757  16.7  73    6.1     3.0  0.356    30  1.31     1.1   \n",
       "9     3.3  31.9  0.879  21.7  77    7.8     7.1  0.439    52  1.28     3.1   \n",
       "22    4.6  35.9  0.785  17.6  79    6.6     2.7  0.300    34  1.19     0.8   \n",
       "5     4.2  32.7  0.914  23.8  80    8.2     8.1  0.443    51  1.42     3.6   \n",
       "19    4.7  34.4  0.803  18.5  78    7.3     0.3  0.462    46  1.25     0.2   \n",
       "24    3.8  29.6  0.882  17.3  77    6.3     3.6  0.380    30  1.26     1.4   \n",
       "25    4.6  34.2  0.827  17.3  62    6.1     4.5  0.304    42  1.10     1.4   \n",
       "30    5.7  36.2  0.760  16.9  82    6.1     1.5  0.310    33  1.22     0.5   \n",
       "23    5.4  33.2  0.795  17.4  81    6.5     0.2  0.176    33  1.32     0.0   \n",
       "16    2.9  34.2  0.752  19.3  74    8.5     0.1  0.333    37  1.18     0.0   \n",
       "\n",
       "    FTM/G    FG%  PTS/48  GS            fullname   PTS  FGA/G  Group  Distance  \n",
       "2     5.4  0.488    33.6  69       James, LeBron  1743   18.5      2  0.000000  \n",
       "11    5.0  0.455    28.5  67           Gay, Rudy  1432   16.4      2  2.928869  \n",
       "15    4.9  0.445    26.8  76     Hayward, Gordon  1463   14.3      2  3.423804  \n",
       "10    4.6  0.470    32.4  62        Wade, Dwyane  1331   17.5      2  3.485929  \n",
       "8     4.2  0.468    28.6  75       Irving, Kyrie  1628   16.5      2  3.555443  \n",
       "14    5.9  0.462    24.8  65       Butler, Jimmy  1301   14.0      2  3.649827  \n",
       "6     4.3  0.466    31.7  71  Aldridge, LaMarcus  1661   19.9      2  3.667809  \n",
       "7     4.6  0.502    29.9  67      Griffin, Blake  1469   17.1      2  3.685176  \n",
       "0     8.1  0.426    39.3  67  Westbrook, Russell  1886   22.0      2  3.722021  \n",
       "12    4.2  0.434    28.2  82     Lillard, Damian  1720   16.6      2  3.967624  \n",
       "3     5.5  0.535    32.4  68      Davis, Anthony  1656   17.6      2  4.088982  \n",
       "4     7.2  0.467    33.9  59   Cousins, DeMarcus  1421   18.1      2  4.297432  \n",
       "13    6.0  0.413    27.5  60      DeRozan, DeMar  1204   16.5      2  4.327920  \n",
       "20    3.6  0.436    24.1  71     Oladipo, Victor  1292   15.1      2  4.499264  \n",
       "17    3.5  0.485    26.3  82         Paul, Chris  1564   14.3      2  4.502929  \n",
       "21    3.6  0.412    24.7  70         Lowry, Kyle  1244   14.9      2  4.541434  \n",
       "28    4.4  0.447    23.6  81       Bledsoe, Eric  1377   12.9      2  4.626776  \n",
       "1     8.8  0.440    35.7  81       Harden, James  2217   18.1      2  4.681894  \n",
       "18    2.9  0.445    26.9  80        Ellis, Monta  1513   16.9      2  4.712634  \n",
       "31    3.5  0.476    24.5  73       Millsap, Paul  1218   12.7      2  4.788322  \n",
       "9     2.9  0.463    32.6  77      Thompson, Klay  1668   16.9      2  4.834636  \n",
       "22    3.6  0.445    23.5  79          Wall, John  1387   14.8      2  4.851901  \n",
       "5     3.9  0.487    34.9  80      Curry, Stephen  1900   16.8      2  4.887398  \n",
       "19    3.8  0.494    25.9  78          Gasol, Pau  1446   14.8      2  4.989331  \n",
       "24    3.3  0.459    28.0  77      Nowitzki, Dirk  1333   13.8      2  5.007452  \n",
       "25    3.8  0.385    24.4  58       Walker, Kemba  1075   15.8      2  5.170208  \n",
       "30    4.3  0.437    22.4  82     Wiggins, Andrew  1387   13.9      2  5.178627  \n",
       "23    4.3  0.494    25.2  81         Gasol, Marc  1413   13.2      2  5.463590  \n",
       "16    2.2  0.523    27.1  74     Vucevic, Nikola  1428   16.3      2  5.780306  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def calculate_distance(s1, s2):\n",
    "    return np.sqrt(np.power(s1 - s2, 2).sum(axis=1))\n",
    "\n",
    "james = players[players.fullname == 'James, LeBron']\n",
    "james_group = players.Group == james.Group.iloc[0]\n",
    "\n",
    "distances = calculate_distance(normalized_stat[james_group], normalized_stat.loc[james.index].iloc[0])\n",
    "distances.name = 'Distance'\n",
    "pd.concat([players[james_group], distances], axis=1).sort_values(by='Distance')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>FTA/G</th>\n",
       "      <th>MPG</th>\n",
       "      <th>FT%</th>\n",
       "      <th>PPG</th>\n",
       "      <th>GP</th>\n",
       "      <th>FGM/G</th>\n",
       "      <th>3FGA/G</th>\n",
       "      <th>3FG%</th>\n",
       "      <th>HIGH</th>\n",
       "      <th>PPS</th>\n",
       "      <th>3FGM/G</th>\n",
       "      <th>FTM/G</th>\n",
       "      <th>FG%</th>\n",
       "      <th>PTS/48</th>\n",
       "      <th>GS</th>\n",
       "      <th>fullname</th>\n",
       "      <th>PTS</th>\n",
       "      <th>FGA/G</th>\n",
       "      <th>Group</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Group</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.9</td>\n",
       "      <td>36.4</td>\n",
       "      <td>0.863</td>\n",
       "      <td>21.7</td>\n",
       "      <td>75</td>\n",
       "      <td>7.7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.415</td>\n",
       "      <td>57</td>\n",
       "      <td>1.32</td>\n",
       "      <td>2.1</td>\n",
       "      <td>4.2</td>\n",
       "      <td>0.468</td>\n",
       "      <td>28.6</td>\n",
       "      <td>75</td>\n",
       "      <td>Irving, Kyrie</td>\n",
       "      <td>1628</td>\n",
       "      <td>16.5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.8</td>\n",
       "      <td>29.1</td>\n",
       "      <td>0.872</td>\n",
       "      <td>14.2</td>\n",
       "      <td>68</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.1</td>\n",
       "      <td>0.342</td>\n",
       "      <td>52</td>\n",
       "      <td>1.12</td>\n",
       "      <td>1.8</td>\n",
       "      <td>2.4</td>\n",
       "      <td>0.397</td>\n",
       "      <td>23.4</td>\n",
       "      <td>33</td>\n",
       "      <td>Williams, Mo</td>\n",
       "      <td>964</td>\n",
       "      <td>12.6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.9</td>\n",
       "      <td>19.8</td>\n",
       "      <td>0.581</td>\n",
       "      <td>7.2</td>\n",
       "      <td>79</td>\n",
       "      <td>2.9</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.345</td>\n",
       "      <td>36</td>\n",
       "      <td>1.22</td>\n",
       "      <td>0.4</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.487</td>\n",
       "      <td>17.4</td>\n",
       "      <td>5</td>\n",
       "      <td>Booker, Trevor</td>\n",
       "      <td>567</td>\n",
       "      <td>5.9</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.8</td>\n",
       "      <td>29.2</td>\n",
       "      <td>0.814</td>\n",
       "      <td>17.2</td>\n",
       "      <td>72</td>\n",
       "      <td>7.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.100</td>\n",
       "      <td>35</td>\n",
       "      <td>1.25</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.1</td>\n",
       "      <td>0.513</td>\n",
       "      <td>28.3</td>\n",
       "      <td>44</td>\n",
       "      <td>Lopez, Brook</td>\n",
       "      <td>1236</td>\n",
       "      <td>13.7</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.5</td>\n",
       "      <td>19.6</td>\n",
       "      <td>0.657</td>\n",
       "      <td>7.9</td>\n",
       "      <td>70</td>\n",
       "      <td>3.4</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.216</td>\n",
       "      <td>27</td>\n",
       "      <td>1.37</td>\n",
       "      <td>0.2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.589</td>\n",
       "      <td>19.4</td>\n",
       "      <td>17</td>\n",
       "      <td>Johnson, James</td>\n",
       "      <td>554</td>\n",
       "      <td>5.8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       FTA/G   MPG    FT%   PPG  GP  FGM/G  3FGA/G   3FG%  HIGH   PPS  3FGM/G  \\\n",
       "Group                                                                           \n",
       "2        4.9  36.4  0.863  21.7  75    7.7     5.0  0.415    57  1.32     2.1   \n",
       "1        2.8  29.1  0.872  14.2  68    5.0     5.1  0.342    52  1.12     1.8   \n",
       "3        1.9  19.8  0.581   7.2  79    2.9     1.1  0.345    36  1.22     0.4   \n",
       "4        3.8  29.2  0.814  17.2  72    7.0     0.1  0.100    35  1.25     0.0   \n",
       "0        1.5  19.6  0.657   7.9  70    3.4     0.7  0.216    27  1.37     0.2   \n",
       "\n",
       "       FTM/G    FG%  PTS/48  GS        fullname   PTS  FGA/G  Group  \n",
       "Group                                                                \n",
       "2        4.2  0.468    28.6  75   Irving, Kyrie  1628   16.5      2  \n",
       "1        2.4  0.397    23.4  33    Williams, Mo   964   12.6      1  \n",
       "3        1.1  0.487    17.4   5  Booker, Trevor   567    5.9      3  \n",
       "4        3.1  0.513    28.3  44    Lopez, Brook  1236   13.7      4  \n",
       "0        1.0  0.589    19.4  17  Johnson, James   554    5.8      0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col = 'HIGH'\n",
    "players.groupby(by='Group').apply(lambda x: x.loc[x[col].idxmax()]).sort_values(by=col, ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "kmeans2 = KMeans(n_clusters=5, random_state=999)\n",
    "kmeans2 = kmeans2.fit(normalized_stat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jaccard similarity of James group: 0.68\n"
     ]
    }
   ],
   "source": [
    "ans1 = set(idx for idx, group in enumerate(kmeans.labels_) if group == kmeans.labels_[james.index])\n",
    "ans2 = set(idx for idx, group in enumerate(kmeans2.labels_) if group == kmeans2.labels_[james.index])\n",
    "print('Jaccard similarity of James group: %.2f' % (len(ans1 & ans2) / len(ans1 | ans2), ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
